#region Imports

using System;
using IEC.ColumnOrdering.SP2007.Application.Domain;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;

#endregion

namespace IEC.ColumnOrdering.SP2007.Application.Services.Concrete
{

    /// <summary>
    /// Provides functionality to convert sites.
    /// </summary>
    internal static class SiteConverter
    {

        #region Constants

        #endregion

        #region Methods - Static Member

        /// <summary>
        /// Converts the given SharePoint site collection to a collection of sites.
        /// </summary>
        /// <param name="sharepointSiteCollection">
        /// The SharePoint site collection to be converted.
        /// </param>
        /// <returns>
        /// The result of converting <paramref name="sharepointSiteCollection"/>.
        /// </returns>
        public static SiteCollection Convert(SPSiteCollection sharepointSiteCollection)
        {
            SiteCollection siteCollection = new SiteCollection();

            foreach (SPSite sharepointSite in sharepointSiteCollection)
            {
                Site site = SiteConverter.Convert(sharepointSite);

                siteCollection.Add(site);
            }

            return siteCollection;
        }

        /// <summary>
        /// Converts the given SharePoint site to a site.
        /// </summary>
        /// <param name="sharepointSite">
        /// The SharePoint site to be converted.
        /// </param>
        /// <returns>
        /// The result of converting <paramref name="sharepointSite"/>.
        /// </returns>
        public static Site Convert(SPSite sharepointSite)
        {
            Site site = new Site();

            // set properties
            site.Id = sharepointSite.ID;
            site.Name = sharepointSite.Url;
            site.DisplayName = sharepointSite.Url;
            site.Url = new Uri(sharepointSite.Url);

            return site;
        }

        #endregion

    }

}
